<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="search" @input="ser" />
    <MyTab
      :records="search === '' ? records : newArr"
      :flag="flag"
      @xq="xiugai"
      @abc="quxiao"
    ></MyTab>
  </div>
</template>

<script>
import MyTab from './components/MyTab.vue'

export default {
  data () {
    return {
      records: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药'
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药'
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴'
        }
      ],
      search: '',
      newArr: [],
      flag: false
    }
  },
  methods: {
    ser () {
      this.newArr = this.records.filter(item => item.doctor === this.search)
    },
    xiugai () {
      this.flag = true
    },
    quxiao () {
      this.flag = false
    }
  },
  components: {
    MyTab
  }
}
</script>

<style>
.my-table {
  border-collapse: collapse;
  width: 100%;
}

.my-table td,
.my-table th {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.my-table th {
  background-color: #f2f2f2;
}
</style>
